//
//  CommonNewsItemViewModel.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/10/19.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "CommonNewsItemViewModel.h"

#import "ArticleListData.h"
#import "CollectionListData.h"

@interface CommonNewsItemViewModel ()

/// 商品模型
//@property (nonatomic, readwrite, strong) EnterpriseInfoData* epInfoData;

@property (nonatomic, copy) NSString* title;
@property (nonatomic, copy) NSString* tag;
@property (nonatomic, copy) NSString* time;
@property (nonatomic, copy) NSString* imgurl;

@end

@implementation CommonNewsItemViewModel

- (instancetype)initWithData:(id)data cellHeight:(CGFloat)cellHeight
{
    self = [super init];
    if (self)
    {
        //        _epInfoData = data;
        
        _data = data;
        
        /// cellHeight+2（2容错）
        _cellHeight = MHUIScaleValue(cellHeight)+2;
        
        @weakify(self);
        [[RACObserve(self, data) distinctUntilChanged] subscribeNext:^(id x)
        {
            @strongify(self);
            
            if ([x isKindOfClass:[ArticleListData class]])
            {
                ArticleListData* alistData = x;
                
                self.title = alistData.title;
                self.tag = alistData.from;
                self.time = alistData.addTime;
                self.imgurl = alistData.thumb;
            }
            else if ([x isKindOfClass:[CollectionListData class]])
            {
                CollectionListData* clistData = x;
                
                self.title = clistData.articleInfo.title;
                self.tag = /*clistData.articleInfo.from*/@"缺参";
                self.time = clistData.articleInfo.addTime;
                self.imgurl = clistData.articleInfo.thumb;
            }
        }];
    }
    
    return self;
}

@end
